package com.com.lease.web.admin.custom.converter;

import com.com.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;

//@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String code) {
        //ItemType.class.getEnumConstants();//获取所有枚举实例  同ItemType.values()
        for (ItemType value : ItemType.values()) {
            if (value.getCode().equals(Integer.valueOf(code))) {
                return value;
            }
        }
        throw new IllegalArgumentException("code"+code+"非法");
    }
}
